#!/usr/bin/python




import os  
import os.path
import time
import sched
import shutil  
  
folder_capacity = 10000  
def copy_files(src_dir, dest_dir):  
    count = 0  
    current_folder = ''   
    for item in os.listdir(src_dir):  
        abs_item = os.path.join(src_dir, item)  
        if os.path.isfile(abs_item):  
            count += 1  
            if count%folder_capacity == 1:  
                current_folder = os.path.join(dest_dir, str(count/folder_capacity))  
                os.mkdir(current_folder)  
            open(os.path.join(current_folder, item), 'wb').write(open(abs_item, 'rb').read())  
        if count<20000:  
            continue  
        else:  
            break  
  
def copy_file(source_dir,target_dir):  
    count=0  
    for item in os.listdir(source_dir):  
        source_files=os.path.join(source_dir,item)  
        if not os.path.exists(target_dir):  
            os.mkdir(target_dir)  
        target_files = os.path.join(target_dir,item)  
        count +=1  
        open(target_files,'wb').write(open(source_files,'rb').read())  
          
        if count>1000:  
            break  
          
def move_file(source_dir,target_dir):  
    count = 0  
    for item in os.listdir(source_dir):  
        source_files=os.path.join(source_dir,item)  
        if not os.path.exists(target_dir):  
            os.mkdir(target_dir)  
        target_files = os.path.join(target_dir,item)  
        count +=1  
        open(target_files,'wb').write(open(source_files,'rb').read())  
        os.remove(source_files)  
        if count>=1041:  
            break  
  
if __name__ =='__main__':  
	os.system("pbjs -t commonjs game.proto > game.js")
	s = sched.scheduler(time.time,time.sleep)

	#s.enter(2,1,move_file,('./','../test'))
	s.enter(2,1,shutil.copyfile,('./game.js','../../assets/Script/MobileKit/Network/game.js'))
	s.run()
        print 'Resolve Done!'
    #move_file('./','../test') 
    























